﻿using CarbonFiberDetection.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CarbonFiberDetection.View
{
    /// <summary>
    /// DetectionWindow.xaml 的交互逻辑
    /// </summary>
    public partial class DetectionWindow
    {
        public DetectionWindowViewModel viewModel;
        public DetectionWindow()
        {
            InitializeComponent();
            viewModel = new DetectionWindowViewModel();
            this.DataContext = viewModel;

            Dispatcher.ShutdownStarted += OnDispatcherShutdownStarted;
        }

        private void OnDispatcherShutdownStarted(object sender, EventArgs e)
        {
            var dataContext = this.DataContext as DetectionWindowViewModel;
            if(dataContext != null && dataContext.CurrentCamera != null)
            {
                if(dataContext.CurrentCamera.IsConnect)
                    dataContext.CurrentCamera?.CloseCamera();
            }
        }

        private void hwindow1_HInitWindow(object sender, EventArgs e)
        {
            var dataContext = this.DataContext as DetectionWindowViewModel;
            if (dataContext != null)
            {
               dataContext.hWindow = this.hwindow1.HalconWindow;
            }
        }
    }
}
